package j04zuoye;
/*
矩形
定义一个矩形类(Rectangle), 包含一个起始点(矩形左上角的点)startPoint, 宽(width), 高(height)属性. 矩形类具有如下方法:
计算面积的方法area,
计算周长的方法perimeter,
获取矩形中心点的方法center(此方法的返回值类型是Point),
打印矩形信息的方法printRectangleInfo,
矩形是否是正方形的方法isSquare, 如果是正方形返回true, 如果不是返回false.

startPoint的类型是Point
 */
class Rectangle{
    Point startPoint;
    double width;
    double height;

    public Rectangle() {
    }

    public Rectangle(Point startPoint, double width, double height) {
        this.startPoint = startPoint;
        this.width = width;
        this.height = height;
    }

    public Point center(){
        Point center = new Point();
        center.x = startPoint.x+width/2;
        center.y = startPoint.y-height/2;
        return center;
    }

    public void printRectangleInfo() {
        System.out.println(
                "Rectangle{" +
                "startPoint=" + startPoint +
                ", width=" + width +
                ", height=" + height +
                '}'
        );
    }

    public boolean isSquare(){
        return width==height;
    }
}
public class Z2juxing {
    public static void main(String[] args) {
        Rectangle r1 = new Rectangle(
                new Point(10,30),
                40,
                20
        );
        System.out.println(r1.center());//?
        r1.printRectangleInfo();
    }
}
